package com.example.drive

import android.content.Context

/**
 * 查看答题情况的适配器
 */
class DrivingAnswerAdapter(context: Context, list: List<DrivingAnswer>, itemLayoutRes: Int) :
    CommonAdapter<DrivingAnswer>(context, list, itemLayoutRes) {

    private val drawableMap by lazy {
        mapOf(
            DrivingAnswer.UNFINISHED to R.drawable.answer_unfinish, // 没有答题,显示白色
            DrivingAnswer.RIGHT to R.drawable.answer_right, // 答题正确,显示绿色
            DrivingAnswer.WRONG to R.drawable.answer_wrong // 答题错误,显示红色
        )
    }

    override fun getItemViewId(): IntArray = intArrayOf(R.id.tv_number, R.id.imageView)

    override fun getView(viewHolder: ViewHolder, position: Int, item: DrivingAnswer) {
        // position从0开始的,题目编号从1开始,需要+1
        viewHolder.setTextView(R.id.tv_number, (position + 1).toString())
            .setImageView(R.id.imageView, drawableMap[item] ?: R.drawable.answer_unfinish)
    }
}